package com.cspg.ssss.vo.convert;

import com.cspg.ssss.domain.CompanyRectifyViewEntity;
import com.cspg.ssss.domain.DeptRectifyViewEntity;
import com.cspg.ssss.util.DateUtil;
import com.cspg.ssss.vo.CompanyRectifyViewVo;
import com.cspg.ssss.vo.DeptRectifyViewVo;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DeptRectifyViewVoConvert {

    public static DeptRectifyViewVo ConvertFromViewEntity(DeptRectifyViewEntity en) {
        DeptRectifyViewVo vo = new DeptRectifyViewVo();
        vo.setId(en.getId());

        vo.setDepartment_name(en.getDepartment_name());

        vo.setPerson_name(en.getPerson_name());

        vo.setInstance_title(en.getInstance_title());

        vo.setCreatea_time(en.getCreatea_time());

        vo.setIsover(en.getIsover());

        vo.setDatafrom(en.getDatafrom());

        vo.setDytxdy(en.getDytxdy());

        vo.setDytxys(en.getDytxys());

        vo.setWtyzcd(en.getWtyzcd());

        vo.setGlhj(en.getGlhj());

        vo.setDwmc(en.getDwmc());

        vo.setWtlb(en.getWtlb());

        vo.setKhbm(en.getKhbm());

        vo.setWtfxsj(en.getWtfxsj());

        vo.setXh(en.getXh());

        vo.setWtms(en.getWtms());

        vo.setGbyy(en.getGbyy());

        vo.setBmmc(en.getBmmc());

        vo.setSscm(en.getSscm());

        vo.setYwsx(en.getYwsx());

        vo.setZylb(en.getZylb());

        vo.setSfzdbl(en.getSfzdbl());

        vo.setSfslwt(en.getSfslwt());

        vo.setWtfxfs(en.getWtfxfs());

        vo.setWtfxr(en.getWtfxr());

        vo.setZgjy(en.getZgjy());

        vo.setProblem_id(en.getProblem_id());

        vo.setDuty_dept(en.getDuty_dept());

        if(en.getDuty_date() != null){
            vo.setDuty_date(new SimpleDateFormat("yyyy-MM-dd").format(en.getDuty_date()));
        }


        vo.setRectify_content(en.getRectify_content());

        if(en.getRectify_deadline() != null){
            vo.setRectify_deadline(new SimpleDateFormat("yyyy-MM-dd").format(en.getRectify_deadline()));
        }


        vo.setManage_dept(en.getManage_dept());

        vo.setReview_dept(en.getReview_dept());

        vo.setRectify_commit(en.getRectify_commit());

        if(en.getRectify_commit_date() != null){
            vo.setRectify_commit_date(new SimpleDateFormat("yyyy-MM-dd").format(en.getRectify_commit_date()));
        }

        if(en.getComplete_date() != null) {
            vo.setComplete_date(new SimpleDateFormat("yyyy-MM-dd").format(en.getComplete_date()));
        }

        if(en.getRectify_status() == null || en.getRectify_status().equals("")){
            vo.setRectify_status("unprocess");
        }else {
            vo.setRectify_status(en.getRectify_status());
        }

        vo.setProblem_type(en.getProblem_type());

        vo.setFlow_type(en.getFlow_type());

        if (en.getRectify_status() != null && en.getRectify_status().equals("duty") && DateUtil.workDaysPeriod(en.getDuty_date(), new Date()) > 5) {
            vo.setPlanoutdate(true);
        } else {
            vo.setPlanoutdate(false);
        }

        Date judgeDate = new Date();
        if (en.getComplete_date() != null) {
            judgeDate = en.getComplete_date();
        }

        vo.setRectifyoutdate(false);
        if (en.getRectify_deadline() != null && judgeDate.compareTo(en.getRectify_deadline()) > 0) {
            vo.setRectifyoutdate(true);
        }

        return vo;
    }

    public static List<DeptRectifyViewVo> ConvertList(List<DeptRectifyViewEntity> enList) {
        List<DeptRectifyViewVo> retList = new ArrayList<DeptRectifyViewVo>();
        for (DeptRectifyViewEntity en : enList) {
            DeptRectifyViewVo vo = new DeptRectifyViewVo();
            vo = ConvertFromViewEntity(en);
            retList.add(vo);
        }
        return retList;
    }
}
